#include<iostream>
#include<unistd.h>
#include<pthread.h>
using namespace std;

//创建一个临界资源
int count = 0;

void* routine(void* msg)
{
    //打印count
    while(true)
    {
        cout<<count<<"-----"<<getpid()<<endl;
        sleep(1);
    }
}

int main()
{
    pthread_t tid;
    //创建新线程
    pthread_create(&tid,nullptr,routine, (void*)"thread 1");

    //主线程对共享资源++
    while(true)
    {
        count++;
        sleep(1);
    }
    return 0;
}